/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upf.editor;

import com.sun.media.jai.codec.JPEGEncodeParam;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageEncoder;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.media.jai.PlanarImage;

/**
 *
 * @author beto
 */
public class JPGsave {

    public JPGsave(File path, PlanarImage img, float qual)
            throws FileNotFoundException, IOException {
        OutputStream out = new FileOutputStream(path);

        //Convert to JPEG with quality selected and store
        JPEGEncodeParam encodeParam = new JPEGEncodeParam();
        encodeParam.setQuality(qual);
        ImageEncoder encoder = ImageCodec.createImageEncoder("JPEG", out, encodeParam);
        encoder.encode(img);

    }
}
